package com.yds.ydsdatasetbackend.manager;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class InitRabbitMq {
    public static void doInit() {
        try {
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("localhost");
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();
            String EXCHANGE_NAME = "file_exchange";
            channel.exchangeDeclare(EXCHANGE_NAME, "direct");

            //创建队列
            String queueName1 = "file_message_queue";
            channel.queueDeclare(queueName1, true, false, false, null);
            channel.queueBind(queueName1, EXCHANGE_NAME, "my_routingKey");
            log.info("启动成功:"+queueName1);

            //创建队列
            String queueName2 = "file_train_queue";
            channel.queueDeclare(queueName2, true, false, false, null);
            channel.queueBind(queueName2, EXCHANGE_NAME, "my_routingKey1");
            log.info("启动成功:"+queueName2);

            //创建队列
            String queueName3 = "file_predict_queue";
            channel.queueDeclare(queueName3, true, false, false, null);
            channel.queueBind(queueName3, EXCHANGE_NAME, "my_routingKey2");
            log.info("启动成功:"+queueName3);

        }catch (Exception e) {
           log.error("启动失败");
        }
    }
    public static void main(String[] args) {
        doInit();
    }
}
